<template>

  <!--

    对话框：选择工艺施工的工序

    -->
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectProcessExecDetail.title"
             :visible.sync="visible"
             width="1100px">

    <!-- 检索条件 -->
    <el-form :model="queryParams" :inline="true" label-width="68px">

      <el-input v-model="queryParams.processExecUuid" v-show="false"/>

      <!-- 编号 -->
      <el-form-item label="施工编号" prop="docNum">
        <el-input
          v-model="queryParams.docNum"
          placeholder="工艺施工编号模糊查询"
          clearable
          size="small"
          @keyup.enter.native="getList"
        />
      </el-form-item>

      <!-- 名称 -->
      <el-form-item label="单据日期" prop="docDt">
        <el-input
          v-model="queryParams.docDt"
          placeholder="请选择日期范围"
          clearable
          size="small"
          @keyup.enter.native="getList"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
                   @click="getList">搜索</el-button>
      </el-form-item>
    </el-form>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="detailList" row-key="taskDetailUuid"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" prop="orderNum"/>
      <el-table-column label="代码" align="center" prop="mesDictProcessCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_code" :value="scope.row.mesDictProcessCode"/>
        </template>
      </el-table-column>
      <el-table-column label="工序类型" align="center" prop="mesDictProcessType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_type" :value="scope.row.mesDictProcessType"/>
        </template>
      </el-table-column>
      <el-table-column label="工序名称" align="center" prop="mesDictProcessName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_name" :value="scope.row.mesDictProcessName"/>
        </template>
      </el-table-column>
      <el-table-column label="设备类型" align="center" prop="wmsDictDeviceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_dict_device_type" :value="scope.row.wmsDictDeviceType"/>
        </template>
      </el-table-column>
      <el-table-column label="工序内容" align="center" prop="processContent"/>
      <el-table-column label="标准定额" align="center" prop="quotaQtyMin"/>
      <el-table-column label="是否复制" align="center" prop="sysYesNoCopy">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoCopy"/>
        </template>
      </el-table-column>
      <el-table-column label="是否质检" align="center" prop="sysYesNoQc">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoQc"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="sysNormalDisable">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.sysNormalDisable"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="docNote"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button type="success" plain size="small" icon="el-icon-check" @click="select_done(scope)">选择</el-button>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="hideDialog">取 消</el-button>
    </div>

  </el-dialog>

</template>

<script>
import {listTask} from "@/api/mes/tasks";
import {listProcessExec} from "@/api/mes/processExec";
import { listProcessExecDetails } from "@/api/mes/processExecDetails";
import {listTaskDetails, listTaskDetailsByTaskUuid} from "@/api/mes/taskDetails";
export default {
  dicts: ['sys_normal_disable','mes_dict_process_name','mes_dict_process_type','sys_yes_no','mes_dict_process_code','wms_dict_device_type'],
  props: {
    // 角色编号
    roleId: {
      type: [Number, String]
    },
  },
  data() {
    return {
      processExecUuid: '',
      detailList: [],
      dialog_selectProcessExecDetail: {
        visible: false,
        showSearch: true,
        title: "请选择物料",
        total: 0,
        taskList: [],
        queryParams:{
          pageNum: 1,
          pageSize: 10,
          parentUuid: '0',
          fkProcessDetailUuid: null,
          orderDetailUuid: null,
          selectedAttentionUser:null,
          fkAttentionUserId:null,
          sysYesNoDone: null,
          mesDictQuotaLevel: null,
          quotaPerMinutes: null,
          quotaTotalMinutes: null
        }
      },
      processExecDetailList:[],
      fold_form_order: 'false',
      // 遮罩层
      loading: true,
      show1: false,
      // 遮罩层
      visible: false,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        parentUuid: '0',
        roleId: undefined,
        userName: undefined,
        phonenumber: undefined,
        taskUuid: undefined
      },
      selectedUser: {
        id: null,
        nickName: null,
        userName: null
      }
    };
  },
  created() {
  },
  methods: {

    /** 读取列表：订单 */
    getList() {
      this.loading = true;
      console.log(this.processExecUuid)
      if(this.processExecUuid == undefined) {
        this.processExecUuid = "未选择派工单"
      }
      listProcessExecDetails({processExecUuid: this.processExecUuid}).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 显示弹框
    show() {
      this.getList()
      this.visible = true;
      this.dialog_selectProcessExecDetail.title = "选择工序";
    },


    // 对话框：隐藏 - 选择物料
    hideDialog() {
      this.visible = false;
    },

    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },

    /** 已选择工艺施工，准备选择工序 */
    select_processExec_done(scope){

      listProcessExecDetails({processExecUuid: scope.row.processExecUuid}).then(response => {
        console.log(response)
        this.processExecDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 已选择工艺施工，准备选择工序 */
    select_done(scope){
      console.log(scope)

      scope.row.mesDictProcessCode = this.selectDictLabel(this.dict.type.mes_dict_process_code, scope.row.mesDictProcessCode)
      scope.row.mesDictProcessName = this.selectDictLabel(this.dict.type.mes_dict_process_name, scope.row.mesDictProcessName)
      scope.row.mesDictProcessType = this.selectDictLabel(this.dict.type.mes_dict_process_type, scope.row.mesDictProcessType)

      this.$emit("ok", scope.row );
      this.hideDialog()
    },

    // 多选完成
    selectTaskDetailsDone() {
      this.$emit("ok", this.taskDetailUuids );
      this.hideDialog()
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection)
      this.taskDetailUuids = selection.map(item => item.taskDetailUuid);
      console.log(this.taskDetailUuids)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList()
    },


    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
